<?php

//UMA new
namespace App\Http\Controllers\Api;

use App\Http\Requests\ScoreInfoPostRequest;
use App\Models\CustomerHistory;
use App\Services\ScoreService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;
use App\Events\CustomerHistoryCreated;
use Auth;
use App\Http\Resources\ScoreResource;

class ScoreController extends BaseController
{
    
    /**
     * score API Entrance.
     * スコア計算入口
     *
     * @param ScoreInfoPostRequest $request
     * @return JsonResponse
     */
    public function store(ScoreInfoPostRequest $request)
    {
        $datas = $request->all();
        $datas = $datas['input']?? $datas;
        $user = Auth::user();
        $customerHistory = $user->histories()->create([
            'input_info' => $datas,
            'temporary_member_id' => $user->temporary_member_id,
        ]);
        event(new CustomerHistoryCreated($customerHistory));
        return new ScoreResource($customerHistory);
    }
}
